﻿namespace Shortcuts.Commands
{
    using System;
    using System.Windows.Input;

    public sealed class Command : ICommand
    {
        Action<object> execute;

        bool isEnabled;

        public bool IsEnabled
        {
            get
            {
                return isEnabled;
            }
            set
            {
                if (isEnabled != value)
                {
                    isEnabled = value;
                    if (CanExecuteChanged != null)
                    {
                        CanExecuteChanged(this, EventArgs.Empty);
                    }
                }
            }
        }

        public Command(Action<object> execute)
        {
            this.execute = execute;
            isEnabled = true;
        }

        public bool CanExecute(object parameter)
        {
            return isEnabled;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (execute != null)
            {
                execute(parameter);
            }
        }
    }
}